package test.kryonet.client;

import java.io.IOException;
import java.util.Scanner;

import test.kryonet.network.DataType1;
import test.kryonet.network.Network;

import com.esotericsoftware.kryonet.Client;
import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener;

public class RunClass {
	public static void main(String[] args ) throws IOException {
		final Client client = new Client();
		Network.register(client);
		client.addListener(new Listener() {
			@Override
			public void connected(Connection connection) {
				System.out.println("Client> connected");
			}

			@Override
			public void disconnected(Connection connection) {
				System.out.println("Client> disconnected");
				client.stop();
				System.exit(-1);
			}

			@Override
			public void received(Connection connection, Object object) {
			//	System.out.println("Client> received something");
			}
			
		});
		new Thread(client).start();
		client.connect(Network.TIME_OUT, Network.HOST_ADRESS, Network.PORT_TCP);
		
		new Thread() {
			@Override
			public void run() {
				Scanner in = new Scanner(System.in);
				String s="";
				while ( true) {
					if (in.hasNextLine()) {
						s = in.nextLine();
						if (s.equals("quit")) break;
						if ( s.equals("send enum")) client.sendTCP(DataType1.ANENUM);
						else client.sendTCP(s);
					}
				}
				client.close();
				in.close();
			}
		}.start();
		//client.sendTCP(new DataType1("this is the first part "));
		//client.stop();
	}
}
